package day_2022_12_to_3.day;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author haomin
 * @date 2022/12/07 23:01
 **/
public class Day12_7_Review {
    class Solution {
        public boolean isValid(String str) {
            if(str.length() == 1) return false;
            Deque<Character> s = new LinkedList<>();
            char[] ch = str.toCharArray();
            for(char c : ch) {
                if(s.isEmpty()) s.push(c);
                else if(!s.isEmpty() && s.peek() == '(') {
                    if(c == ')') s.poll();
                    else s.push(c);
                }
                else if(!s.isEmpty() && s.peek() == '[') {
                    if(c == ']') s.poll();
                    else s.push(c);
                }
                else if(!s.isEmpty() && s.peek() == '{') {
                    if(c == '}') s.poll();
                    else s.push(c);
                }
            }
            return s.isEmpty();
        }
    }
}